﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SQLite;
using System.Data.Common;

namespace skydream
{
    /// <summary>
    /// mobile的sqllite 数据读取操作
    /// </summary>
    public class sqlLiteMobile
    {

        /// <summary>
        /// 根据文件名直接生成db3文件
        /// </summary>
        /// <param name="fileDb3"></param>
        /// <returns></returns>
        public static SQLiteConnection getConn(string fileDb3)
        {
            SQLiteConnection myconn = new SQLiteConnection("Data Source=" + fileDb3);
            return myconn;
        }

        //
        // 摘要:
        //     sql基本查询（根据链接，查询命令）
        //
        // 返回结果:
        //     返回dataSet集合
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sqliteConn"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataSet getBasicTable(SQLiteConnection sqliteConn, string sql)
        {
            //首先查询reflow_table
            SQLiteCommand cmd = new SQLiteCommand();//sqllite命令
            cmd.Connection = sqliteConn;
            //DbTransaction  trans = sqliteConn.BeginTransaction();
            SQLiteDataAdapter slda = new SQLiteDataAdapter();//sqlite适配器

            cmd.CommandText = sql;
            slda.SelectCommand = cmd;//查询操作
            DataSet ds = new DataSet();
            slda.Fill(ds);

            return ds;
        }
        //
        // 摘要:
        //     sql简单插入操作（根据链接，插入命令）
        //
        // 返回结果:
        //     返回null
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sqliteConn"></param>
        /// <param name="sql"></param>
        public static void insertCmd(SQLiteConnection sqliteConn, string sql)
        {
            SQLiteCommand mycmd = new SQLiteCommand();
            mycmd.Connection = sqliteConn;
            mycmd.CommandText = sql;
            mycmd.ExecuteNonQuery();
        }
    }
}
